<?php
class sendmail extends DBservice
{
    function send($str)
    {
        $mail = new phpmailer(); //声明类
        $mail->IsSMTP(); // 设置使用 SMTP
        $mail->Host = "mail.weixun.co"; // 指定的 SMTP 服务器地址
        $mail->SMTPAuth = true; // 设置为安全验证方式
        $mail->Username = "ceibs@weixun.co"; // SMTP 发邮件人的用户名
        $mail->Password = "ceibsweibo0"; // SMTP 密码
        $mail->From = "ceibs@weixun.co";
        $mail->FromName = "中欧乐活管理员";
        $mail->AddAddress($str['mail']);
        $mail->WordWrap = 50; // 50字折行
        //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 加附件
        //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // 附件，也可选加命名附件
        $mail->IsHTML(true); // 设置邮件格式为 HTML
        $mail->Subject = $str['subject']; // 标题
        $mail->Body = $str['body']; // 内容
        //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
        if (!$mail->Send()) {
            $str['mailstatus']=0;
            self::sendlog($str);
            return "发送出错!详情: " . $mail->ErrorInfo;
        } else {
            $str['mailstatus']=1;
            self::sendlog($str);
            return $str['mail'] . "发送成功!";
        }
    }
    
    function sendlog($str){
        $sql = "insert into sendmaillog (mailclass,userid,mailsubject,mailbody,mailto,mailstatus,maildate) VALUES ('" . 
        $str['mailclass'] . "','" . $str['userid'] . "','" . $str['subject'] . "','" . mysql_escape_string($str['body']) . "','" . $str['mail'] . "','" . $str['mailstatus']
        . "','" . time() . "')";
        $this->insertdb($sql);
    }
}

?>